import requests
class add:
    cookies = {
        'JSESSIONID': '11AC16CF9DFAE1882DA67904E8ED81D6',
        'tempTokenKey': 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6bnVsbCwicm9sZSI6IlJPTEVfQVJFQSxST0xFX1dJTkRPVyIsImlzSW5pdGlhbFBhc3N3b3JkIjoiMCIsInJlZ2lvbk5hbWUiOiLotLXlt57nnIEiLCJpbmR1c3RyeSI6bnVsbCwiYXBwQ29kZSI6ImRnb3YtcG9ydGFsIiwib3JnYW5OYW1lIjoi5LqR5LiK6LS15beeIiwicmVnaW9uQ29kZSI6IjUyMDAwMCIsImluZHVzdHJ5TGlzdCI6bnVsbCwib3JnYW5Db2RlIjoiNTIwMDAyIiwiZXhwaXJhdGlvblRpbWUiOjM2LCJncmFkZSI6IjIiLCJzdGF0dXMiOiIxIiwiaXNzIjoiaW5zcHVyIiwiaWF0IjoxNzIxNDYxMjMzLCJleHAiOjE3MjE0OTAwMzN9.VUiuLacBRphyu2vg6-GwTI5BxNpAksqDSv3eIq00d4Fq2UESALBrlONpfULp0ShMNONoc_-949gD-_3X614hxA',
        'userInfoKey': '{^%^22role^%^22:^%^22ROLE_AREA^%^2CROLE_WINDOW^%^22^%^2C^%^22isInitialPassword^%^22:^%^220^%^22^%^2C^%^22regionName^%^22:^%^22^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^E7^%^9C^%^81^%^22^%^2C^%^22appCode^%^22:^%^22dgov-portal^%^22^%^2C^%^22organName^%^22:^%^22^%^E4^%^BA^%^91^%^E4^%^B8^%^8A^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^22^%^2C^%^22regionCode^%^22:^%^22520000^%^22^%^2C^%^22phone^%^22:^%^22384d53fa06a4844cfd54260b048c33e9^%^22^%^2C^%^22organCode^%^22:^%^22520002^%^22^%^2C^%^22expirationTime^%^22:36^%^2C^%^22name^%^22:^%^221342b48e6f8f39ea7ba36accc05b61a8^%^22^%^2C^%^22id^%^22:^%^229E1059C9335D4C7CB8DC7400D03AECFB^%^22^%^2C^%^22email^%^22:^%^22aa67c9bf293c42e9144476195b550c0f^%^22^%^2C^%^22username^%^22:^%^2247d57692a252657367001b6a2ff35333^%^22^%^2C^%^22status^%^22:^%^221^%^22^%^2C^%^22isWeakPwd^%^22:^%^220^%^22}',
        'pwdState': 'true',
        'inspurRoleKey': 'ROLE_AREA',
        'windowId': '0B7CA12E92004E0ABCA9EB88F0A792E4',
        'James_cookie_sYQDUGqqzHtheme': 'custom',
    }

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        # 'Accept-Encoding': 'gzip, deflate',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'X-Requested-With': 'XMLHttpRequest',
        'Origin': 'http://61.243.3.187:82',
        'Connection': 'keep-alive',
        'Referer': 'http://61.243.3.187:82/zhslzy/accept/monitor/allbusiness/index',
        # 'Cookie': 'JSESSIONID=11AC16CF9DFAE1882DA67904E8ED81D6; tempTokenKey=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6bnVsbCwicm9sZSI6IlJPTEVfQVJFQSxST0xFX1dJTkRPVyIsImlzSW5pdGlhbFBhc3N3b3JkIjoiMCIsInJlZ2lvbk5hbWUiOiLotLXlt57nnIEiLCJpbmR1c3RyeSI6bnVsbCwiYXBwQ29kZSI6ImRnb3YtcG9ydGFsIiwib3JnYW5OYW1lIjoi5LqR5LiK6LS15beeIiwicmVnaW9uQ29kZSI6IjUyMDAwMCIsImluZHVzdHJ5TGlzdCI6bnVsbCwib3JnYW5Db2RlIjoiNTIwMDAyIiwiZXhwaXJhdGlvblRpbWUiOjM2LCJncmFkZSI6IjIiLCJzdGF0dXMiOiIxIiwiaXNzIjoiaW5zcHVyIiwiaWF0IjoxNzIxNDYxMjMzLCJleHAiOjE3MjE0OTAwMzN9.VUiuLacBRphyu2vg6-GwTI5BxNpAksqDSv3eIq00d4Fq2UESALBrlONpfULp0ShMNONoc_-949gD-_3X614hxA; userInfoKey={^%^22role^%^22:^%^22ROLE_AREA^%^2CROLE_WINDOW^%^22^%^2C^%^22isInitialPassword^%^22:^%^220^%^22^%^2C^%^22regionName^%^22:^%^22^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^E7^%^9C^%^81^%^22^%^2C^%^22appCode^%^22:^%^22dgov-portal^%^22^%^2C^%^22organName^%^22:^%^22^%^E4^%^BA^%^91^%^E4^%^B8^%^8A^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^22^%^2C^%^22regionCode^%^22:^%^22520000^%^22^%^2C^%^22phone^%^22:^%^22384d53fa06a4844cfd54260b048c33e9^%^22^%^2C^%^22organCode^%^22:^%^22520002^%^22^%^2C^%^22expirationTime^%^22:36^%^2C^%^22name^%^22:^%^221342b48e6f8f39ea7ba36accc05b61a8^%^22^%^2C^%^22id^%^22:^%^229E1059C9335D4C7CB8DC7400D03AECFB^%^22^%^2C^%^22email^%^22:^%^22aa67c9bf293c42e9144476195b550c0f^%^22^%^2C^%^22username^%^22:^%^2247d57692a252657367001b6a2ff35333^%^22^%^2C^%^22status^%^22:^%^221^%^22^%^2C^%^22isWeakPwd^%^22:^%^220^%^22}; pwdState=true; inspurRoleKey=ROLE_AREA; windowId=0B7CA12E92004E0ABCA9EB88F0A792E4; James_cookie_sYQDUGqqzHtheme=custom',
        'Priority': 'u=1',
    }

    def query_window(self,name):
        data = '_search=true&nd=1721380949302&rows=10&page=1&sidx=sort&sord=asc&windowShowCode=&windowName={}&userName=&itemCode=&itemName=&hallName=&regionName=遵义&orgName=&orgCode='.format(name).encode('utf-8')

        response = requests.post('http://61.243.3.187:82/zhslzy/accept/system/window/query', cookies=self.cookies,
                                 headers=self.headers, data=data).json()
        for item in response['rows']:
           re=item['cell']['WINDOW_ID']

        return re

    def query_item(self,name):
        params = {
            'listType': 'item',
            'limitType': 'all',
        }

        data = 'itemCode=&itemName={}&type=&orgName=遵义市政务服务局&orgCode=009500051&regionName=&regionCode=&_search=true&nd=1721381344233&rows=10&page=1&sidx=SUBMIT_TIME&sord=desc'.format(name).encode('utf-8')

        response = requests.post(
            'http://61.243.3.187:82/zhslzy/accept/component/list/query',
            params=params,
            cookies=self.cookies,
            headers=self.headers,
            data=data,
        ).json()
        list=[]
        for item in response['rows']:
            ID=item['cell']['ID']
            NAME=item['cell']['NAME']
            CODE=item['cell']['CODE']
            ORG_CODE=item['cell']['ORG_CODE']
            ORG_NAME=item['cell']['ORG_NAME']
            REGION_CODE=item['cell']['REGION_CODE']
            REGION_NAME=item['cell']['REGION_NAME']
            FOLDER_ID=item['cell']['FOLDER_ID']
            FOLDER_NAME=item['cell']['FOLDER_NAME']
            list.append({
                'ID': ID,
                'NAME': NAME,
                'CODE': CODE,
                'ORG_CODE': ORG_CODE,
                'ORG_NAME': ORG_NAME,
                'REGION_CODE': REGION_CODE,
                'REGION_NAME': REGION_NAME,
                'FOLDER_ID': FOLDER_ID,
                'FOLDER_NAME': FOLDER_NAME
            })
            #print(ID,NAME,CODE,ORG_CODE,ORG_NAME,REGION_CODE,REGION_NAME,FOLDER_ID,FOLDER_NAME)

        #print(list)
        return list


    def add_item(self,name):
        window_id = self.query_window(name)
        print(window_id)
        addItems=self.query_item(name)
        print(addItems)
        params = {
            'method': 'saveItems',
        }

        data = {
            "windowId": "{}".format(window_id),
            "addItems": addItems,
            "delItems": []
        }
        response = requests.post(
            'http://61.243.3.187:82/zhslzy/accept/system/window',
            params=params,
            cookies=self.cookies,
            headers=self.headers,
            json=data,
        ).json()
        print(response)

    def start(self):
        name=[
            '樊文艳',
            '唐维',
            '杨瑛梓',
            '张乙涵',
            '朱玉叶',
            '詹兴星',
            '刘豪',
            '贾玉梅',
            '李洪梅',
            '孙小松',
            '姚晨晨',
            '符艺淋',
            '雷平星',
            '母永利',
            '王素',
            '丁塑红',
            '姚仕霞',
            '杨小燕',
            '李航丽',
            '陈宇星',
            '王维维',
            '吴金燕',
            '贾凌云',
            '王树树',
            '黄宇',
            '陈婷',
            '甘志清',
            '韦小燕',
            '张勤',
            '岺继美',
            '冯杰',
            '简小丽',
            '丁宇杰',
            '彭霞',
            '王红霞',
            '杨艳',
            '岳秀梅',
            '黎静',
            '郑继力',
            '白露',
            '姚凤',
            '文静',
            '罗传叶',
            '张洁',
            '宋紫玲',
            '杨满',
            '李应维',
            '周骥',
            '刘丽春',
            '石娅',
            '周显东',
            '陈小兰',
            '张玲娇',
            '赵明书',
            '郭韦玮',
            '李碧雨',
            '喻萍',
            '宋晓艳',
            '毛远兰',
            '汪夕人',
            '黄富琴',
            '赵倩',
            '陈小明',
            '刘畅',
            '熊世君',
            '张文兰',
            '邹登琴',
            '余小兰',
            '倪雪',
            '张志颖',
            '陈媛',
            '卢涛',
            '杨静',
            '李天敏',
            '陆龙红',
            '符迁迁',
            '周泽宇',
            '付娜娜',
            '冯鹏博',
            '赵勋'

        ]
        for i in name:
            self.add_item(i)
add().start()
